function videoClick(newSrcID, videoID) {
    var video = document.getElementById(videoID);
    var newSrc = document.getElementById(newSrcID).value;
    video.setAttribute("src", newSrc);
	
	video.load();
	
	video.play();
	return false;				
}

function videoJump(nextPositionID, videoID) {
    var video = document.getElementById(videoID);
    var nextPosition = document.getElementById(nextPositionID).value;

    video.currentTime = nextPosition;
    return false;		
}

function ctrClick(checkID, videoID){
	var video = document.getElementById(videoID);
	var check = document.getElementById(checkID);
	if (video.hasAttribute("controls") && !check.checked) {
		video.removeAttribute("controls");   
	} else if (!video.hasAttribute("controls") && check.checked) {
		video.setAttribute("controls","controls");   
	}
}

function rotateVideo(angleTextID, videoID) {
    var angle = document.getElementById(angleTextID).value;

    if (!angle || angle == "undefined" || isNaN(angle))
        return false;

    var properties = ['transform', 'WebkitTransform', 'MozTransform',
	                  'msTransform', 'OTransform'];

    var video = document.getElementById(videoID);

    var property = properties[0];
    for (var i = 0, j = properties.length; i < j; i++) {
        if (typeof video.style[properties[i]] !== 'undefined') {
            property = properties[i];
            break;
        }
    }

    video.style[property] = 'rotate(' + angle + 'deg)';

    return true;
}

function getPreview(previewCanvasID, videoID) {
    var video = document.getElementById(videoID);
    var canvas = document.getElementById(previewCanvasID);


    canvas.width = video.videoWidth;
    canvas.height = video.videoheight;

    if (canvas.height == 0 || canvas.width == 0)
        return false;

    var ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0);
}

function mirrorVideo(videoID) {
    var video = document.getElementById(videoID);

    if (video.style.cssText == "") {
        window.mirrored = true;
        video.style.cssText = "-moz-transform: scale(-1, 1); -webkit-transform: scale(-1, 1); -o-transform: scale(-1, 1); transform: scale(-1, 1); filter: FlipH;";
        return;
    }

    if (window.mirrored) {
        video.style.cssText = "-moz-transform: scale(1, 1); -webkit-transform: scale(1, 1); -o-transform: scale(1, 1); transform: scale(1, 1);";
        window.mirrored = false;
    }
    else if (!window.mirrored) {
        video.style.cssText = "-moz-transform: scale(-1, 1); -webkit-transform: scale(-1, 1); -o-transform: scale(-1, 1); transform: scale(-1, 1); filter: FlipH;";
        window.mirrored = true;
    }
}

var curVideo = "video-1";
function changeVideo(videoID) {
	var video = document.getElementById('jukeBoxVideo');
    var nextVideo = document.getElementById(videoID);
	if (nextVideo) {
		video.setAttribute("src", nextVideo.getAttribute('value'));
		curVideo = videoID;
		video.load();
		video.play();
	}

    return false;		
}


